from models import db
from datetime import datetime
from models.Courses import *


class UserModels(db.Model):
    """用户"""
    __tablename__ = 'tb_user'
    uid = db.Column(db.Integer, primary_key=True, autoincrement=True, doc='用户id')
    account = db.Column(db.String(32), doc='账号')
    phone = db.Column(db.String(16), doc='手机号')
    password = db.Column(db.String(256), doc='密码')
    nick_name = db.Column(db.String(32), doc='昵称')
    profile_photo = db.Column(db.String(256), doc='头像')
    last_login = db.Column(db.DateTime, doc='最后登录时间')
    address = db.Column(db.String(256), doc='地址')
    is_superuser = db.Column(db.Integer, default=0, doc='0普通用户1管理员2超级管理员')
    register_time = db.Column(db.DateTime, doc='注册时间', default=datetime.now())
    comment = db.relationship('Comments', backref='comment_user')
    vip = db.relationship('VipModel', backref='vip_user')


class OAuthUserModel(db.Model):
    '''
    三方登录的表，记录当前三方登录和用户的关系
    '''
    __tablename__ = 'oauth_user'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True ,doc='oauth_user id')
    image = db.Column(db.String(256), doc='头像')
    oauth_id = db.Column(db.String(512), doc='第三方登录的id')
    user = db.Column(db.Integer, db.ForeignKey("tb_user.uid", ondelete="CASCADE"))
    oauth_type = db.Column(db.String(128), doc='第三方登录类型')


class VipModel(db.Model):
    """vip表"""
    __tablename__ = 'tb_vip'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    title = db.Column(db.String(128), doc='vip名称')
    level = db.Column(db.Integer, default=0, doc='vip等级(0普通用户,1普通会员2高级会员)')
    price = db.Column(db.DECIMAL(13, 2), doc='会员价格')
    desc = db.Column(db.String(64), doc='vip描述')
    period = db.Column(db.Integer, default=365, doc='vip有效期')
    exempt_cour = db.Column(db.Integer, doc='免费课程{0或空:不享受,1:享受}')
    vip_cour = db.Column(db.Integer, doc='会员课程{0或空:不享受,1:享受}')
    environment = db.Column(db.Integer, doc='实验环境联网{0或空:不享受,1:享受}')
    save = db.Column(db.Integer, doc='保存2个环境(30天){0或空:不享受,1:享受}')
    client = db.Column(db.Integer, doc='客户端{0或空:不享受,1:享受}')
    ssh = db.Column(db.Integer, doc='SSH直连{0或空:不享受,1:享受}')
    web_ide = db.Column(db.Integer, doc='WebIDE {0或空:不享受,1:享受}')
    discounts = db.Column(db.Integer, doc='训练营优惠{0或空:不享受,1:享受}')
    exempt_study = db.Column(db.Integer, doc='训练营课程免费学习{0或空:不享受,1:享受}')
    user = db.Column(db.Integer, db.ForeignKey('tb_user.uid', ondelete="CASCADE"))
